<?php

/**
 * Area actions.
 *
 * @package    wills
 * @subpackage Area
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class AreaActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeShow(sfWebRequest $request)
  {
    $this->area = Doctrine::getTable('Area')
      ->findOneBySlug($request->getParameter('area'));
      
    $this->categories = Doctrine::getTable('Category')
      ->retrieveInOrderQuery()
      ->execute();
    
    // 大赛头条
    $this->hots = $this->area
      ->getHeadlinesWithChildrenQuery()
      ->execute();
    
    // 最新动态
    $this->latest = $this->area->getArticleByCategoryQuery('大赛动态')->limit(10)->execute();
    
    // 公告
    $this->bulletin = $this->area->getArticleByCategoryQuery('官方公告')
      ->select('id, title, created_at')
      ->limit(9)
      ->execute();
      
    // 选手名次
	
    $this->contestants = $this->area
      ->getContestantsQuery($order='default')
      ->execute();
    
    $this->pollForm = new PollLogForm2();
    
    // 精彩照片
    $this->primary   = $this->area->getPhotoByCategoryQuery('预选赛')->limit(4)->execute();
    $this->semifinal = $this->area->getPhotoByCategoryQuery('半决赛')->limit(4)->execute();
    $this->final     = $this->area->getPhotoByCategoryQuery('总决赛')->limit(4)->execute();
    
    // 视频播报
    $this->report = $this->area->getVideoByCategoryQuery('视频播报')->execute();
    
    // 独家视频
    $this->exclusive = $this->area->getVideoByCategoryQuery('独家视频')->limit(4)->execute();
  
    // 唯一指定
    $this->sponsored = $this->area->getArticleByCategoryQuery('唯一指定')->execute();
    
    // 组委会动态
    $this->activity = $this->area->getArticleByCategoryQuery('组委会动态')->limit(10)->execute();

    // 媒体关注
    $this->media = $this->area->getArticleByCategoryQuery('媒体关注')->limit(10)->execute();
    
    // 政府关注
    $this->gov   = $this->area->getArticleByCategoryQuery('政府关注')->limit(6)->execute();
    
    // 幕后花絮
    $this->behindTheScene = $this->area->getArticleByCategoryQuery('幕后花絮')->limit(4)->execute();
    
    // 最新动态 
    $this->latestImage = $this->area->getImageByCategoryQuery('最新动态')->limit(3)->execute();
    
    // 大赛评委
    $this->judge = $this->area->getImageByCategoryQuery('大赛评委')->limit(8)->execute();
    
    // 特别策划
    $this->plans = $this->area->getArticleByCategoryQuery('特别策划')->limit(2)->execute();
    
    // 媒体报道
    $this->mediaImage = $this->area->getImageByCategoryQuery('媒体报道')->limit(1)->execute();
    
    // 政府关注
    $this->govImage = $this->area->getImageByCategoryQuery('政府关注')->limit(1)->execute();
    
    // 幕后花絮
    $this->behindTheSceneImage = $this->area->getImageByCategoryQuery('幕后花絮')->limit(1)->execute();
    
    // 旅游资讯
    $this->travelImage = $this->area->getImageByCategoryQuery('旅游资讯')->limit(3)->execute();
    
    // 专区幻灯
    $this->slideShow = $this->area->getImageByCategoryQuery('专区幻灯')->limit(5)->execute();
    
    // 鸣谢
    $this->thanks = $this->area->getImageByCategoryQuery('鸣谢')->limit(4)->execute();
    
    // 合作伙伴
    $this->partners = $this->area->getImageByCategoryQuery('合作伙伴')->limit(15)->execute();
  }
  
  public function executePoll(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));
    
    $this->form = new PollLogForm2();
    $this->form->bind($request->getParameter('poll_log'));
    
    if ($this->form->isValid())
    {
      $this->getUser()->setFlash('message', '投票成功！');
      $this->redirect('@area?area=' . $request->getParameter('area'));
    }
    
    $this->setTemplate(sfConfig::get('sf_app_module_dir') . '/Contestant/templates/poll');
  }
}
